@echo off
REM ===========================================================================
REM Copyright 2011 Cardpad, Inc. All rights reserved.
REM CARDPAD PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
REM
REM Author  : Y.Volta AT gmail.com
REM Version : 1.0
REM Modified: 2011/10/01 07:55
REM ===========================================================================

echo.
echo  ************************* Javacard applet builder *************************
echo.

setlocal

set APP_ID=0xA0:0x00:0x00:0x00:0x03:0x00:0x00:0x00
set PKG_ID=0xA0:0x00:0x00:0x00:0x03:0x01:0x08

set PKG_NAME=calc
set PKG_FULL_NAME=com.cardpad.calc
set PKG_PATH=com\cardpad\calc
set APP_CLASS=CalcApplet

if "%JAVA_HOME%" == "" goto WARN_NOJHOME
if "%JC_HOME%" == "" goto WARN_NOJCHOME

REM echo y| rd /s com\sun\javacard\impl\javacard
 
echo. 1. compiling...
call %JAVA_HOME%\bin\javac -target 1.5 -d %OUTPUT_DIR% -g %PKG_PATH%\*.java
echo.

echo. 2. converting...
cd output
call  %JC_HOME%\bin\converter -nobanner -debug -i -exportpath .;%JC_HOME%\api_export_files -out CAP -applet %APP_ID% %PKG_FULL_NAME%.%APP_CLASS% %PKG_FULL_NAME% %PKG_ID% 1.0
cd ..
echo.

echo. 3. generate scr file
call scriptgen -nobanner -o %APP_CLASS%.scr %OUTPUT_DIR%\%PKG_PATH%\javacard\%PKG_NAME%.cap
echo.

echo. 4. update the cap in scripts\res directory
copy %OUTPUT_DIR%\%PKG_PATH%\javacard\%PKG_NAME%.cap %OUTPUT_DIR%\%PKG_NAME%.cap > nul
copy %OUTPUT_DIR%\%PKG_PATH%\javacard\%PKG_NAME%.cap ..\scripts\res\%PKG_NAME%.cap > nul
echo.

echo  Done!
echo.
goto END

:WARN_NOJHOME
echo  No JAVA_HOME environment.
goto END

:WARN_NOJCHOME
echo  No JC_HOME environment.
goto END

:END

REM ================================================== End of Script ===========
